cmake_minimum_required(VERSION 3.5)
project(ipa_room_segmentation)

if (NOT CMAKE_CXX_STANDARD)
    set(CMAKE_CXX_STANDARD 14)
endif ()

if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
    add_compile_options(-Wall -Wextra -Wpedantic)
endif ()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-pedantic")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-sign-compare")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-variable")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-but-set-variable")

find_package(ament_cmake REQUIRED)
find_package(cv_bridge REQUIRED)
find_package(rclcpp REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(nav_msgs REQUIRED)
find_package(nav2_msgs REQUIRED)
find_package(rclcpp_action REQUIRED)
find_package(ipa_building_msgs REQUIRED)
find_package(OpenCV REQUIRED)
find_package(OpenMP)
find_package(tf2_ros REQUIRED)

if (OPENMP_FOUND)
    message(STATUS "OPENMP FOUND")
    set(OpenMP_FLAGS ${OpenMP_CXX_FLAGS})  #${OpenMP_C_FLAGS}
    set(OpenMP_LIBS gomp)
endif ()

set(dependencies
        rclcpp_action
        cv_bridge
        ipa_building_msgs
        nav_msgs
        tf2_ros
        nav2_msgs
        rclcpp
        sensor_msgs
        )

###########
## Build ##
###########
## Specify additional locations of header files
## Your package locations should be listed before other locations
# include_directories(include ${catkin_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS})
# important: common/include also needs to be here if you have it
include_directories(
        include
        common/include
        ros/include
        ${OpenCV_INCLUDE_DIRS}
)

# library of the created algorithms
add_library(${PROJECT_NAME} SHARED
        common/src/distance_segmentation.cpp
        common/src/morphological_segmentation.cpp
        common/src/abstract_voronoi_segmentation.cpp
        common/src/voronoi_segmentation.cpp
        #common/src/adaboost_classifier.cpp
        common/src/wavefront_region_growing.cpp
        common/src/contains.cpp common/src/features.cpp
        common/src/raycasting.cpp
        common/src/meanshift2d.cpp
        common/src/room_class.cpp
        #common/src/voronoi_random_field_segmentation.cpp
        common/src/clique_class.cpp
        common/src/cv_boost_loader.cpp
        common/src/voronoi_random_field_features.cpp
        )
target_link_libraries(${PROJECT_NAME}
        ${OpenCV_LIBRARIES}
        )
ament_target_dependencies(${PROJECT_NAME} ${dependencies})

### segmentation action server: see room_segmentation_action_server_params.yaml to change the used method
add_executable(room_segmentation_server
        ros/src/room_segmentation_server.cpp
        )
target_link_libraries(room_segmentation_server
        ${OpenMP_LIBS}
        ${OpenCV_LIBRARIES}
        ${PROJECT_NAME})
ament_target_dependencies(room_segmentation_server ${dependencies})

### client for testing purpose
add_executable(room_segmentation_client ros/src/room_segmentation_client.cpp)
target_link_libraries(room_segmentation_client
        ${OpenCV_LIBRARIES})
ament_target_dependencies(room_segmentation_client ${dependencies})

### evaluation function for numeric properties and comparison to a given ground truth segmentation
add_executable(evaluation
	ros/src/evaluation_numeric_properties.cpp
	common/src/evaluation_segmentation.cpp)
target_link_libraries(evaluation ${OpenCV_LIBRARIES})
ament_target_dependencies(evaluation  ${dependencies} )


#############
## Install ##
#############
## Mark executables and/or libraries for installation
install(TARGETS ${PROJECT_NAME}
        room_segmentation_server
        room_segmentation_client
        evaluation
        ARCHIVE DESTINATION lib
        LIBRARY DESTINATION lib
        RUNTIME DESTINATION lib/${PROJECT_NAME}
        )
install(DIRECTORY common/include/${PROJECT_NAME}/
        DESTINATION include/${PROJECT_NAME}/
        )
##uncomment this if you have a common-directory with header-files
install(DIRECTORY ros/include/${PROJECT_NAME}/
        DESTINATION include/${PROJECT_NAME}/
        )

##uncomment this if you use launch and yaml files
install(DIRECTORY ros/launch
        DESTINATION share/${PROJECT_NAME}
        )

#install(DIRECTORY common/files
#	DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/common
#	PATTERN ".svn" EXCLUDE
#)
ament_package()
